home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / The_Last_H20903111112007.psc / The Last Hope / DirectX.cls < prev    next >
Text File  |  2007-11-11  |  2KB  |  65 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "DirectX"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. 'Controls direct sound operations
  15.  
  16. Public Sub Initialize()
  17.  Dim Buffer As DSBUFFERDESC
  18.  Dim Format As WAVEFORMATEX
  19.  
  20. 'On Local Error Resume Next
  21. 'Create Direct sound
  22. Set DS = TheDx.DirectSoundCreate("")
  23. If Err.Number <> 0 Then
  24. MsgBox "Sorry You Don't Have DirectX installed", vbCritical
  25. Exit Sub
  26. End If
  27. DS.SetCooperativeLevel frmMain.hWnd, DSSCL_NORMAL
  28. 'Create Direct sound Buffer
  29. Buffer.lFlags = DSBCAPS_CTRLVOLUME Or DSBCAPS_CTRLFREQUENCY
  30. With Format
  31.     .nFormatTag = WAVE_FORMAT_PCM
  32.     .nChannels = 2
  33.     .nBitsPerSample = 16
  34.     .nBlockAlign = .nBitsPerSample \ 8 * .nChannels
  35.     .lAvgBytesPerSec = .lSamplesPerSec * .nBlockAlign
  36. End With
  37. Set DB(0) = DS.CreateSoundBufferFromFile(App.Path + "\sound\Background.wav", Buffer, Format)
  38. Set DB(1) = DS.CreateSoundBufferFromFile(App.Path + "\sound\Kaboom.wav", Buffer, Format)
  39. Set DB(2) = DS.CreateSoundBufferFromFile(App.Path + "\sound\Kaboomex.wav", Buffer, Format)
  40. Set DB(3) = DS.CreateSoundBufferFromFile(App.Path + "\sound\fire.wav", Buffer, Format)
  41. Set DB(4) = DS.CreateSoundBufferFromFile(App.Path + "\sound\inventory.wav", Buffer, Format)
  42. If MusicOff Then Exit Sub
  43. DB(0).SetVolume -500
  44. DB(0).Play DSBPLAY_LOOPING
  45. End Sub
  46.  
  47. Public Sub Destroy()
  48. Set TheDx = Nothing
  49. Set DS = Nothing
  50. End Sub
  51.  
  52. Public Sub PlayMusic(What As String)
  53. If MusicOff Then Exit Sub
  54. Select Case LCase(What)
  55. Case "fire"
  56. DB(3).Play DSBPLAY_DEFAULT
  57. Case "explosionasteroid"
  58. DB(2).Play DSBPLAY_DEFAULT
  59. Case "explosionship"
  60. DB(1).Play DSBPLAY_DEFAULT
  61. Case "inventory"
  62. DB(4).Play DSBPLAY_DEFAULT
  63. End Select
  64. End Sub
  65.